package com.byjh.quartz.task;

import com.byjh.common.constant.Constants;
import com.byjh.common.utils.StringUtils;
import com.byjh.common.utils.WechatUtils;
import com.byjh.system.service.ISysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 定时任务调度测试
 * 
 * @author dhq
 */
@Component("wechat")
public class WechatTask
{
    private static final String appId = "wx9e9e3e69d7a622f4";
    private static final String appSecret = "17ec672598fd21b9b692553263331c3e";

    @Resource
    private ISysConfigService sysConfigService;

    /**
     * 微信token (每小时执行)
     */
    public void Token() {
        String token = WechatUtils.token(appId, appSecret);
        if(StringUtils.isEmpty(token)) {
            throw new RuntimeException("获取token失败");
        }
        sysConfigService.updateConfigValueByKey(Constants.WECHAT_TOKEN, token);
    }

}
